/****************************************************************
*****************************************************************/

*by Xiaodong Fan, fanxiaodong@gmail.com

#delimit ;

cap log close;
clear all;
drop _all;
set more 1;
pause on;

log using log_MSM_rob_compare_elas.log, replace;

global gpicsdir "pics_rob_compare_elas";

global gdtadir ".";

include do_globals.do;

* The model with higher alpha_I;
* monarch.test2.v2;
use ../test_alpha_I/monarch.test2/dta_MSM_ProfilesMoments.dta, clear;
gen imodel = 2;
compress;
save dta_RR3_temp.dta, replace;

* Version1;
use ../../v19/gadi.nodepatwork/gadi.nodepatwork.v7/dta_MSM_ProfilesMoments.dta, clear;
gen imodel = 221;
compress;
append using dta_RR3_temp.dta;
compress;
save dta_RR3_temp.dta, replace;

* Version2;
use ../gadi.nodepatwork2/gadi.nodepatwork2.v5/dta_MSM_ProfilesMoments.dta, clear;
gen imodel = 222;
compress;
append using dta_RR3_temp.dta;
compress;
save dta_RR3_temp.dta, replace;

* moments for the baseline model;
use dta_MSM_ProfilesMoments.dta, clear;
drop lfpr1 lfpr2 lfpr3 lfpr4 lnw1 lnw2 lnw3 lnw4; // different health status;
gen imodel = 0;
compress;
append using dta_RR3_temp.dta;
compress;
save dta_RR3_temp.dta, replace;

local lvxxs lfpr H H_worker lnH lnH_worker I I_cond lnw lnw_fd sdlnw A C inc;
keep imodel ihet t `lvxxs';
*replace lfpr = . if t==80;

sort ihet t imodel;
reshape wide `lvxxs', i(ihet t) j(imodel);
sort ihet t;


local lvcond1 "t>=18 & t<=80";
local lvcond2 "t>=22 & t<=65";
local lvxlabel1 xlabel(20(10)80);
local lvxlabel2 xlabel(22 30(10)60 65);
local lvfn1 "";
local lvfn2 "65";

local lvlgd0 "Baseline: {&alpha}{sub:I}=0.102";
local lvlgd2 "{&alpha}{sub:I}=0.692";
local lvlgd221 "NoDep@work v1: {&alpha}{sub:I}=0.650";
local lvlgd222 "NoDep@work v2: {&alpha}{sub:I}=0.614";

foreach ivt in 1 2 {;
    * The model with higher alpha_I;
    line I0 I2 t if ihet==0 & `lvcond`ivt'', 
             lpattern("l" "_" "-" "-.") graphregion(color(white))
             ytitle("Investment")  `lvxlabel`ivt''
             yscale(range(0 0.6)) ylabel(0(0.1)0.6) 
             legend(pos(1) ring(0) col(1) region(lwidth(none))
                    order(1 "`lvlgd0'" 2 "`lvlgd2'"));
    graph export ${gpicsdir}/eps_higherI_I`lvfn`ivt''.eps,replace;

    line I_cond0 I_cond2 t if ihet==0 & `lvcond`ivt'', 
             lpattern("l" "_" "-" "-.") graphregion(color(white))
             ytitle("Investment at work") `lvxlabel`ivt'' 
             yscale(range(0 0.6)) ylabel(0(0.1)0.6)
             legend(pos(1) ring(0) col(1) region(lwidth(none))
                    order(1 "`lvlgd0'" 2 "`lvlgd2'"));
    graph export ${gpicsdir}/eps_higherI_I_cond`lvfn`ivt''.eps,replace;

    line H0 H2 t if ihet==0 & `lvcond`ivt'', 
             lpattern("l" "_" "-" "-.") graphregion(color(white))
             ytitle("Human capital")  `lvxlabel`ivt''
             // yscale(range(${gyrange_`iv'})) ylabel(${gylabel_`iv'})
             legend(pos(7) ring(0) col(1) region(lwidth(none))
                    order(1 "`lvlgd0'" 2 "`lvlgd2'"));
    graph export ${gpicsdir}/eps_higherI_H`lvfn`ivt''.eps,replace;

    * 221: Version1;
    * 222: Version2;
    line I0 I221 I222 t if ihet==0 & `lvcond`ivt'', 
             lpattern("l" "_" "-" "-.") graphregion(color(white))
             ytitle("Investment") `lvxlabel`ivt'' 
             yscale(range(0 0.6)) ylabel(0(0.1)0.6) 
             legend(pos(1) ring(0) col(1) region(lwidth(none))
                    order(1 "`lvlgd0'" 2 "`lvlgd221'" 3 "`lvlgd222'"));
    graph export ${gpicsdir}/eps_nodepatwork_I`lvfn`ivt''.eps,replace;

    line I_cond0 I_cond221 I_cond222 t if ihet==0 & `lvcond`ivt'', 
             lpattern("l" "_" "-" "-.") graphregion(color(white))
             ytitle("Investment at work")  `lvxlabel`ivt''
             yscale(range(0 0.6)) ylabel(0(0.1)0.6)
             legend(pos(1) ring(0) col(1) region(lwidth(none))
                    order(1 "`lvlgd0'" 2 "`lvlgd221'" 3 "`lvlgd222'"));
    graph export ${gpicsdir}/eps_nodepatwork_I_cond`lvfn`ivt''.eps,replace;

    line lnH0 lnH221 lnH222 lnH_worker0 lnH_worker221 lnH_worker222 t if ihet==0 & `lvcond`ivt'', 
             lpattern("l" "_" "-" "l" "_." "-.") graphregion(color(white))
             ytitle("Human capital")  `lvxlabel`ivt''
             legend(pos(7) ring(0) row(2) region(lwidth(none))
                    order(1 "log(H): Baseline" 2 "v1" 3 "v2"
                          4 "log(H)@work: B" 5 "v1" 6 "v2"));
    graph export ${gpicsdir}/eps_nodepatwork_lnH`lvfn`ivt''.eps,replace;
    line A0 A221 A222 t if ihet==0 & `lvcond`ivt'', 
             lpattern("l" "_" "-" "l" "_." "-.") graphregion(color(white))
             ytitle("Asset")  `lvxlabel`ivt''
             legend(pos(11) ring(0) col(1) region(lwidth(none))
                    order(1 "Baseline" 2 "v1" 3 "v2"));
    graph export ${gpicsdir}/eps_nodepatwork_A`lvfn`ivt''.eps,replace;
    line C0 C221 C222 t if ihet==0 & `lvcond`ivt'', 
             lpattern("l" "_" "-" "l" "_." "-.") graphregion(color(white))
             ytitle("Consumption")  `lvxlabel`ivt''
             legend(pos(6) ring(0) col(1) region(lwidth(none))
                    order(1 "Baseline" 2 "v1" 3 "v2"));
    graph export ${gpicsdir}/eps_nodepatwork_C`lvfn`ivt''.eps,replace;
    line inc0 inc221 inc222 t if ihet==0 & `lvcond`ivt'', 
             lpattern("l" "_" "-" "l" "_." "-.") graphregion(color(white))
             ytitle("Income")  `lvxlabel`ivt''
             legend(pos(6) ring(0) col(1) region(lwidth(none))
                    order(1 "Baseline" 2 "v1" 3 "v2"));
    graph export ${gpicsdir}/eps_nodepatwork_inc`lvfn`ivt''.eps,replace;
    line lnw0 lnw221 lnw222 t if ihet==0 & `lvcond`ivt'', 
             lpattern("l" "_" "-" "l" "_." "-.") graphregion(color(white))
             ytitle("lnw")  `lvxlabel`ivt''
             legend(pos(6) ring(0) col(1) region(lwidth(none))
                    order(1 "Baseline" 2 "v1" 3 "v2"));
    graph export ${gpicsdir}/eps_nodepatwork_lnw`lvfn`ivt''.eps,replace;
    line lfpr0 lfpr221 lfpr222 t if ihet==0 & `lvcond`ivt'', 
             lpattern("l" "_" "-" "l" "_." "-.") graphregion(color(white))
             ytitle("LFPR")  `lvxlabel`ivt''
             legend(pos(6) ring(0) col(1) region(lwidth(none))
                    order(1 "Baseline" 2 "v1" 3 "v2"));
    graph export ${gpicsdir}/eps_nodepatwork_lfpr`lvfn`ivt''.eps,replace;
    line sdlnw0 sdlnw221 sdlnw222 t if ihet==0 & `lvcond`ivt'', 
             lpattern("l" "_" "-" "l" "_." "-.") graphregion(color(white))
             ytitle("S.D. of lnw")  `lvxlabel`ivt''
             legend(pos(6) ring(0) col(1) region(lwidth(none))
                    order(1 "Baseline" 2 "v1" 3 "v2"));
    graph export ${gpicsdir}/eps_nodepatwork_sdlnw`lvfn`ivt''.eps,replace;

    * all together;
    line I0 I2 I221 I222 t if ihet==0 & `lvcond`ivt'', 
             lpattern("l" "_" "-" "-.") graphregion(color(white))
             ytitle("Investment") `lvxlabel`ivt'' 
             yscale(range(0 0.6)) ylabel(0(0.1)0.6) 
             legend(pos(1) ring(0) col(1) region(lwidth(none))
                    order(1 "`lvlgd0'" 2 "`lvlgd2'" 3 "`lvlgd221'" 4 "`lvlgd222'"));
    graph export ${gpicsdir}/eps_all_I`lvfn`ivt''.eps,replace;

    line I_cond0 I_cond2 I_cond221 I_cond222 t if ihet==0 & `lvcond`ivt'', 
             lpattern("l" "_" "-" "-.") graphregion(color(white))
             ytitle("Investment at work")  `lvxlabel`ivt''
             yscale(range(0 0.6)) ylabel(0(0.1)0.6)
             legend(pos(1) ring(0) col(1) region(lwidth(none))
                    order(1 "`lvlgd0'" 2 "`lvlgd2'" 3 "`lvlgd221'" 4 "`lvlgd222'"));
    graph export ${gpicsdir}/eps_all_I_cond`lvfn`ivt''.eps,replace;

    line H0 H2 H221 H222 t if ihet==0 & `lvcond`ivt'', 
             lpattern("l" "_" "-" "-.") graphregion(color(white))
             ytitle("Human capital")  `lvxlabel`ivt''
             legend(pos(7) ring(0) col(1) region(lwidth(none))
                    order(1 "`lvlgd0'" 2 "`lvlgd2'" 3 "`lvlgd221'" 4 "`lvlgd222'"));
    graph export ${gpicsdir}/eps_all_H`lvfn`ivt''.eps,replace;
};

cap log close;



